<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>用户信息详情</title>
    <link rel="stylesheet" href="../css/page-health-orderInfo.css"/>
    <link rel="stylesheet" href="../plugins/elementui/index.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/datapicker/datePicker.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="https://api.map.baidu.com/api?v=2.0&ak=hw8qc12rpfbBQFSdv4WOmXgSKsOPcUdB&s=1"
            type="text/javascript"></script>
    <script>
        var id = getUrlParam("id");
    </script>
    <style>
        #containermap {
            height: 250px;
            width: 400px;
        }

        /*#containermap1{*/
        /*    height: 20px;*/
        /*    width: 20px;*/
        /*}*/
    </style>
</head>
<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">传智健康</span>
        <span class="f-right"><i class="icon-more"></i></span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">


        <div class="form-info">
            <div class="info-title">
                <span class="name">信息详情</span>
            </div>
            <form class="info-form">
                <div class="input-row">
                    <label>用户名</label>
                    <input v-model="setmeal.name" type="text" class="input-clear" placeholder="请输入姓名" disabled
                           id="name">

                </div>
                <div class="input-row single-radio">
                    <label class="radio-title">性别</label>
                    <div class="radio-list">
                        <div class="radio">
                            <input v-model="setmeal.sex" id="item1" type="radio" name="sex" value="1" disabled>
                            <label for="item1"></label>
                            <span>男</span>
                        </div>
                        <div class="radio">
                            <input v-model="setmeal.sex" id="item2" type="radio" name="sex" value="2" disabled>
                            <label for="item2"></label>
                            <span>女</span>
                        </div>
                    </div>
                </div>
                <div class="input-row">
                    <label>手机号</label>
                    <input v-model="setmeal.phoneNumber" type="text" class="input-clear" placeholder="" disabled
                           id="phoneNumber">
                    <input id="validateCodeButton" @click="sendValidateCode()" type="button" style="font-size: 12px"
                           value="获取验证码" disabled>
                    <input v-model="validateCode" style="width:80%" id='password' type="text" placeholder="请输入验证码"
                           disabled>
                </div>
                <div class="input-row">
                    <label>身份证号</label>
                    <input v-model="setmeal.idCard" type="text" class="input-clear" placeholder="" disabled id="idCard">
                </div>
                <div class="input-row">
                    <label>生日</label>
                    <input v-model="setmeal.birthday" type="text" class="input-clear" placeholder="" disabled
                           id="birthday">
                </div>
                <div class="input-row">
                    <label>邮箱</label>
                    <input v-model="setmeal.email" type="text" class="input-clear" placeholder="" disabled id="email">
                </div>
                <div class="input-row">
                    <label>注册日期</label>
                    <input v-model="setmeal.regTime" type="text" class="input-clear" placeholder="" disabled
                           id="regTime">
                </div>
                <div class="input-row">
                    <label>修改个人信息请点击下方进行修改</label>
                </div>
            </form>
            <div class="box-button">
                <button @click="ifsunmit()" type="button" class="btn order-btn" id="111">修改个人信息</button>
            </div>

            <div class="box-button">
                <button @click="updatephoneNumber()" type="button" class="btn order-btn" id="222">修改个人手机号</button>
            </div>
            <div class="box-button">
                <button @click="updatephoneNumber1()" type="button" class="btn order-btn" id="333">确定修改手机号</button>
            </div>
        </div>
    </div>
</div>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            setmeal: {},//套餐信息
            orderInfo: {
                setmealId: id,
                sex: '1'
            },//预约信息
            flag: 1,
            validateCode: "",
        },
        methods: {
            //发送验证码
            sendValidateCode() {
                // orderInfo 双向绑定
                //var telephone = this.orderInfo.telephone;

                // 手机校验不通过
                if (checkTelephone(this.setmeal.phoneNumber)) {
                    //显示倒计时 30s 效果
                    // 根据ID，获取指定组件 ( 左边的 validateCodeButton 是在 healthmobile.js  中定义的变量，我们在这边赋值，那边就可以锁定指定的组件)
                    validateCodeButton = $("#validateCodeButton")[0];
                    //window.setInterval() 自带的方法 可以指定每隔指定的时间，调用我们指定的方法
                    //第一个参数是方法名 ， 第二个参数是 指定的时间(毫秒值)
                    window.setInterval(doLoop, 1000);

                    axios.post("/validateCode/send4update.do?telephone=" + this.setmeal.phoneNumber).then((res) => {
                        if (!res.data.flag) {
                            //短信验证码发送失败
                            this.$message.error(res.data.message);
                            return false;
                        } else {
                            //短信验证码发送成功
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                        }
                    });
                } else {
                    this.$message.error("手机号码输入不正确");
                    return false;

                }

            },


            //提交预约
            submitOrder() {
                //对用户输入的身份证进行校验
                if (checkIdCard(this.setmeal.idCard)) {
                    axios.post("/healthRecordDetailTest/update.do", this.setmeal).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            //跳转到预约成功界面
                            // res.data.data 就是 预约成功后对应的ID
                            location.href = "orderSuccess.html?orderId=" + res.data.data;
                        } else {
                            this.$message.error(res.data.message);
                            return false;
                        }
                    });
                } else {
                    this.$message.error("请输入正确的身份证号码");
                    return false;
                }
            },
            update() {
                $("#name").prop("disabled", false);
                $("#idCard").prop("disabled", false);
                $("#birthday").prop("disabled", false);
                $("#email").prop("disabled", false);
                $("#regTime").prop("disabled", false);
                $("#item1").prop("disabled", false);
                $("#item2").prop("disabled", false);
                $("#111").html("提交确认信息");
            },
            submit() {
                alert("11");
                if (checkIdCard(this.setmeal.idCard)) {
                    axios.post("/healthRecordDetailTest/update.do?validateCode=" + this.validateCode, this.setmeal).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.setmeal=res.data.data;

                        } else {
                            this.$message.error(res.data.message);
                            this.setmeal=res.data.data;
                        }
                    });
                } else {
                    this.$message.error("请输入正确的身份证号码");

                }
                $("#name").prop("disabled", true);
                $("#idCard").prop("disabled", true);
                $("#birthday").prop("disabled", true);
                $("#email").prop("disabled", true);
                $("#regTime").prop("disabled", true);

                $("#item1").prop("disabled", true);
                $("#item2").prop("disabled", true);
                $("#111").html("修改个人信息");

            },
            ifsunmit() {
                if (this.flag == 1) {
                    this.flag = 0;
                    this.update();
                    this.flag = 0;
                } else {
                    this.flag = 1;
                    this.submit();
                    this.flag = 1;
                }
            },
            updatephoneNumber(){
                $("#phoneNumber").prop("disabled", false);
                $("#validateCodeButton").prop("disabled", false);
                $("#password").prop("disabled", false);
            },
            updatephoneNumber1(){
                axios.post("/healthRecordDetailTest/send4updatephoneNumber.do?validateCode=" + this.validateCode,this.setmeal).then((res) => {
                    if (!res.data.flag) {
                        //短信验证码发送失败
                        this.$message.error(res.data.message);
                        this.setmeal=res.data.data;
                    } else {
                        //短信验证码发送成功
                        this.$message({
                            message: res.data.message,
                            type: 'success'
                        });
                        this.setmeal=res.data.data;
                    }
                });
                $("#validateCodeButton").prop("disabled", true);
                $("#password").prop("disabled", true);
                $("#phoneNumber").prop("disabled", true);
            }

        },

        //钩子函数
        mounted() {
            axios.post("/healthRecordDetailTest/getUser.do?").then((response) => {
                if (response.data.flag) {
                    this.setmeal = response.data.data;
                    //alert(response.data.data);
                } else {
                    alert("查询失败")
                }
            });
        }
    });
</script>
</body>
</html>